//delete//
const statusCode = require('../util/status-code')
const getProjectTree = require("../mock/server/getProjectTree");
const getProjectList = require("../mock/server/getProjectList");
const getProjects = require("../mock/server/getProjects");
const getProjectOneTree = require("../mock/server/getProjectOneTree");

//delete//
class BuryPointProjectController {
    /**
     * 创建信息
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async create(ctx) {
        let req = JSON.parse(ctx.request.body);
        if (req.name && req.type) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('创建成功', project)
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('创建成功失败，请求参数不能为空！')
        }
    }

    /**
     * 更新
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async update(ctx) {
        let req = JSON.parse(ctx.request.body);
        let id = req.id;
        if (req) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('更新信息成功！', '');
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('更新信息失败！')
        }
    }

    /**
     * 删除
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async delete(ctx) {
        let param = JSON.parse(ctx.request.body);
        const { id ,type} = param
        // 删除前，先检查是否还有
        if(id && type){
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('success', "")
        }else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('删除失败，请求参数不能为空！')
        }
        
    }

    /**
     * tree
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async tree(ctx) {        
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getProjectTree)
    }

    static async getAllProjectList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getProjectList)
    }
    
    static async getProjectList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getProjects)
    }
    /**
     * 获取单个项目tree
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async getProjectTree(ctx) { 
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getProjectOneTree)
    }
    static async existTemplate(ctx){
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', "0")
    }

    static async getAllList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getProjectList)
    }
}
//exports//
module.exports = BuryPointProjectController
//exports//